package com.atguigu.eduService.controller.front;

import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "前台讲师模块")
@RestController
@RequestMapping("/eduService/teacherFront")
@CrossOrigin
public class TeacherFrontController {

    @Resource
    private EduTeacherService eduTeacherService;
    @Resource
    private EduCourseService eduCourseService;

    @ApiOperation("分页查询讲师")
    @GetMapping("/getTeacherFrontList/{page}/{limit}")
    public Result<Map<String,Object>> getTeacherFrontList(@PathVariable Long page, @PathVariable Long limit) {
        Map<String,Object> eduTeacherMap =  eduTeacherService.getTeacherFrontList(page, limit);
        return ResultUtil.success(eduTeacherMap);
    }

    @ApiOperation("讲师详情")
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    public Result<Map<String,Object>> getTeacherFrontInfo(@PathVariable String teacherId){
        //查询讲师信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //查询课程信息
        QueryWrapper<EduCourse> eduCourseQueryWrapper = new QueryWrapper<>();
        eduCourseQueryWrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduCourseList = eduCourseService.list(eduCourseQueryWrapper);
        Map<String,Object> map = new HashMap<>();
        map.put("eduTeacher",eduTeacher);
        map.put("eduCourseList",eduCourseList);
        return ResultUtil.success(map);
    }

}
